<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增礼品卡')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-card-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">礼品名称：</label>
                <div class="col-sm-8">
                    <select name="productId" class="form-control m-b">
                        <!--<option value="">所有</option>-->
                        <option th:each="pro : ${products}" th:text="${pro.productName}" th:value="${pro.productId}">代码生成请选择字典属性</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">起始码序号：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input id="startCode" name="startCode" class="form-control" type="number" required>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">终止码序号：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input id="endCode" name="endCode" class="form-control" type="number" required>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">礼品有效期（始）：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="startDate" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">礼品有效期（终）：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="endDate" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "core/card"
        $().ready(function() {
            validateRule();
        });
        function validateRule() {
            var icon = "<i class='fa fa-times-circle'></i> ";
            $('#form-card-add').validate({
                focusCleanup: true,
                rules : {
                    startCode : {
                        remote : {
                            url: prefix+"/getCode",
                            type:"POST",
                            data:{
                                index: function () {
                                    return $("#startCode").val();
                                }
                            }
                        }
                    },
                    endCode : {
                        remote : {
                            url: prefix+"/getCode",
                            type:"POST",
                            data:{
                                index: function () {
                                    return $("#endCode").val();
                                }
                            }
                        }
                    }
                },
                messages: {
                    startCode : {
                        remote :icon+ "开始序号已被占用或不存在相应码"
                    },
                    endCode : {
                        remote :icon+ "结束序号已被占用或不存在相应码"
                    }
                }
            })
        }

     /*   $("#form-card-add").validate({

        });*/

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-card-add').serialize());
            }
        }

        $("input[name='startDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='endDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>